package com.cuitrip.config;

import com.cuitrip.mode.Rule;
import com.cuitrip.util.TextUtil;
import org.dom4j.Element;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by MiJack on 2015/11/21.
 */
public class OutputConfig {
    String outputDir;
    List<Rule> list;

    private OutputConfig() {
        list = new ArrayList<Rule>();
    }

    public String getOutputDir() {
        return outputDir;
    }

    public List<Rule> getList() {
        return list;
    }

    public static OutputConfig build(Element output) {
        OutputConfig config = new OutputConfig();
        config.outputDir = output.attributeValue("output-dir");
        List rules = output.elements("rule");
        for (Element element : (List<Element>) rules) {
            Rule rule = Rule.build(element);
            config.list.add(rule);
        }
        return config;
    }

    @Override
    public String toString() {
        return "OutputConfig{" +
                "outputDir='" + outputDir + '\'' +
                ", \nlist=\n" + TextUtil.listToString(list) +
                '}';
    }
}
